<?php
// +-------------------------------------------------------------------
// |
// +-------------------------------------------------------------------
// | Copyright (c) 2009-2016 All rights reserved.
// +-------------------------------------------------------------------
namespace Service\Api\V1;

class ArchivesVisionList
{
    public $login = true; //是否需要登录才能访问该接口
    public $title = "验光记录列表";
    public $group = '档案管理';
    public $desc = "";

    public $input = [
        'id' => 'required;int;label=档案id;',
        'page_num' => 'int;label=分页;comment=默认为1',
        'page_size' => 'int;label=分页条数;comment=默认为5',
    ];

    public $output = [
        'page_num' => 'label=当前页码;',
        'page_size' => 'label=每页条数;',
        'page_count' => 'label=总条数;',
        'page_total' => 'label=总页数;',
        'list' => [
            [
                'id' => 'label=id;',
                'aid' => 'label=档案id;',
                'sph_left' => 'label=左眼度数;',
                'sph_right' => 'label=右眼度数;',
                'pd' => 'label=瞳距;',
                'cyl_left' => 'label=散光左眼;',
                'cyl_right' => 'label=散光右眼;',
                'axi_left' => 'label=左眼轴位;',
                'axi_right' => 'label=右眼轴位;',
                'optometry_time' => 'label=验光日期;',
            ]
        ],
        'archive_info' => [
            'name' => 'label=档案人姓名;',
            'sex' => 'label=性别;comment=1男、2女',
        ],
    ];



    public function run($param, $uid)
    {
        $page_num = $param['page_num'] ?: 1;
        $page_size = $param['page_size'] ?: 5;
        list($list, $page_count, $page_total) = OE('Archives')->visionList($uid, $page_num, $page_size, $param['id']);
        $my_archive = M('eyes_archives')->where(['uid' => $uid, 'relation' => 1])->find();
        if(isset($my_archive['id'])){
            $my_state = 1;
        }else{
            $my_state = 2;
        }
        $archive_info = (array)M('eyes_archives')->where(['id' =>$param['id']])->find();
        return [
            'page_num' => $page_num,
            'page_size' => $page_size,
            'page_count' => $page_count,
            'page_total' => $page_total,
            'list' => $list,
            'archive_info' => $archive_info,
            'my_state' => $my_state,
        ];
    }
}
